﻿using Bouyei.Geo.Geometries;
using Bouyei.Geo.GeoParsers.GeoPackage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.Geo.GeoParsers.Parser
{
    public class GeoPackageParser:IDisposable
    {
        GeometryReader reader = null;
        GeometryWriter writer = null;
        public GeoType GeometryType { get; private set; }
        public int SRID { get; private set; }
        public GeoPackageParser()
        {

        }

        public virtual Geometry FromReader(byte[] buffer, int offset = 0)
        {
            using (reader = new GeometryReader(buffer, offset))
            {
                GeometryType = reader.GeometryType;
                SRID = reader.SRID;
                return reader.Reader();
            }
        }

        public virtual byte[] ToWriter(Geometry geometry)
        {
            writer = new GeometryWriter(geometry);
            return writer.Writer();
        }

        public void Dispose()
        {
            if(reader != null)
                reader.Dispose();

            writer = null;
        }
    }
}
